package com.ruoyi.web.controller.project.meeting;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.project.meeting.MeetingInfo;
import com.ruoyi.system.service.project.IMeetingInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国际学术会议Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/project/meeting")
public class MeetingInfoController extends BaseController
{
    @Autowired
    private IMeetingInfoService meetingInfoService;

    /**
     * 查询国际学术会议列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MeetingInfo meetingInfo)
    {
        startPage();
        List<MeetingInfo> list = meetingInfoService.selectMeetingInfoList(meetingInfo);
        return getDataTable(list);
    }

    /**
     * 导出国际学术会议列表
     */
    @Log(title = "国际学术会议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingInfo meetingInfo,
                       @RequestParam(required = false) String exportFields)
    {
        List<MeetingInfo> list = meetingInfoService.selectMeetingInfoList(meetingInfo);
        ExcelUtil<MeetingInfo> util = new ExcelUtil<MeetingInfo>(MeetingInfo.class);
        // 如果传递了导出字段，则进行处理
        if (StringUtils.isNotBlank(exportFields)) {
            // 将逗号分隔的字段转为数组，调用showColumn指定显示字段
            String[] fields = exportFields.split(",");
            util.showColumn(fields); // 关键：使用ExcelUtil已有的showColumn方法
        }
        util.exportExcel(response, list, "国际学术会议数据");
    }

    /**
     * 获取国际学术会议详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingInfoService.selectMeetingInfoById(id));
    }

    /**
     * 新增国际学术会议
     */
    @Log(title = "国际学术会议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingInfo meetingInfo)
    {
        return toAjax(meetingInfoService.insertMeetingInfo(meetingInfo));
    }

    /**
     * 修改国际学术会议
     */
    @Log(title = "国际学术会议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingInfo meetingInfo)
    {
        return toAjax(meetingInfoService.updateMeetingInfo(meetingInfo));
    }

    /**
     * 删除国际学术会议
     */
    @Log(title = "国际学术会议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingInfoService.deleteMeetingInfoByIds(ids));
    }
}
